﻿using Microsoft.Extensions.DependencyModel;
using ProductService.Model;
using ProductService.Repositorys;
using ProductService.Services.Dtos;
using Servicecomb.Saga.Omega.Abstractions.Transaction;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;

namespace ProductService.Services
{
    /// <summary>
    /// 商品service实现
    /// </summary>
    [Dependency(ServiceLifetime.Transient)]
    public class ProductService : CrudAppService<Product, ProductDto, Guid>, IProductService
    {
        private IProductRepository productRepository;
        public ProductService(IProductRepository repository) : base(repository)
        {
            productRepository = repository;
        }

        public override async Task<ProductDto> UpdateAsync(Guid id, ProductDto input)
        {
            var data = await productRepository.GetAsync(id);
            ObjectMapper.Map(input, data);
            Product product = await productRepository.UpdateAsync(data);
            return ObjectMapper.Map<Product, ProductDto>(product);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<ProductDto> CreateAsync(ProductDto input)
        {
            return await base.CreateAsync(input);
        }
    }
}
